###########################################################################
# Makefile for BPALogin v2.0
##

##
# Install locations as determined by configure
prefix=@prefix@
exec_prefix=@exec_prefix@
SBINPATH=@sbindir@
ETCPATH=@sysconfdir@

##
# Locations of system utilities as determined by configure
CC=@CC@
CHKCONFIG=@CHKCONFIG@
INSTALL=@INSTALL@
SED=@SED@

##
#
CFLAGS=@CFLAGS@ -Wall 
LIBS=@LIBS@
LDFLAGS=@LDFLAGS@

OBJS = bpalogin.o protocol.o transaction.o gen_md5.o unixmain.o

bpalogin: $(OBJS)
	$(CC) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)

.c.o:
	$(CC) $(CFLAGS) -c $<

clean:
	rm -fr *.o

distclean: clean
	rm -f bpalogin config.log config.cache config.status Makefile bpalogin.h

bpalogin.h: bpalogin.h.in
	$(SED) 's#@@BPALOGIN_CONF@@#$(ETCPATH)/bpalogin.conf#' < bpalogin.h.in > bpalogin.h

$(OBJS): bpalogin.h

install: bpalogin bpalogin.init bpalogin.bsd
	case `uname -s` in \
	  Linux*) \
	    mkdir -p $(RPM_BUILD_ROOT)$(ETCPATH)/rc.d/init.d ; \
	    $(INSTALL) -m 755 bpalogin.init \
	               $(RPM_BUILD_ROOT)$(ETCPATH)/rc.d/init.d/bpalogin ; \
	    \
	    if [ -z "$(RPM_BUILD_ROOT)" -a -x "$(CHKCONFIG)" ]; then \
	      $(CHKCONFIG) --add bpalogin ; \
	    fi ; \
	    ;; \
	  \
	  FreeBSD*) \
	    mkdir -p $(ETCPATH)/rc.d ; \
	    $(INSTALL) -m 755 bpalogin.bsd $(ETCPATH)/rc.d/bpalogin.sh ; \
	    ;; \
	    \
	  *) \
	    echo "###" ; \
	    echo "# You will need to add BPALogin to your startup scripts." ; \
	    echo "###" ; \
	    ;; \
	esac ; \
	
	mkdir -p $(RPM_BUILD_ROOT)$(SBINPATH)
	mkdir -p $(RPM_BUILD_ROOT)$(ETCPATH)
	$(INSTALL) -m 755 bpalogin $(RPM_BUILD_ROOT)$(SBINPATH)
	$(INSTALL) -m 600 bpalogin.conf $(RPM_BUILD_ROOT)$(ETCPATH)
